package com.lagou.thread.pool.executor;

import java.util.concurrent.*;

/**
 * @author: lidy
 * @date: 2021/10/8 11:37
 */
public class ExecuteSubmitExample {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 10, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue(20));
        // execute 使用
        executor.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println("Hello, execute.");
            }
        });
        // submit 使用
        Future<String> future = executor.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                System.out.println("Hello, submit.");
                return "Success";
            }
        });
        System.out.println(future.get());
    }
}
